import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' },
    }]
  },




]
export const asyncIndeterminacyRoutes = [{
  path: '/product',
  component: Layout,
  name: 'Product',
  redirect: '/product/trademark',
  meta: { title: '商品', icon: 'el-icon-goods' },
  children: [{
    path: 'trademark',
    name: 'Trademark',
    component: () => import('@/views/product/Trademark/index.vue'),
    meta: { title: '品牌管理' }
  },
  {
    path: 'spu',
    name: 'Spu',
    component: () => import('@/views/product/Spu/Spu.vue'),
    meta: { title: 'Spu管理' }
  },
  {
    path: 'attr',
    name: 'Attr',
    component: () => import('@/views/product/Attr/index.vue'),
    meta: { title: '平台属性管理' }
  },
  ]
}, {
  path: '/acl',
  component: Layout,
  name: 'Acl',
  redirect: '/acl/user',
  meta: { title: '权限管理', icon: 'el-icon-setting' },
  children: [
    {
      name: 'User',
      path: "user",
      component: () => import('@/views/acl/User/User.vue'),
      meta: { title: '用户管理' }
    },
    {
      name: 'Role',
      path: "role",
      component: () => import('@/views/acl/Role/Role.vue'),
      meta: { title: '角色管理' }
    },
    {
      name: 'Permission',
      path: "permission",
      component: () => import('@/views/acl/Permission/Permission.vue'),
      meta: { title: '菜单管理' }
    },
  ]
}]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes,
  mode: 'history',
})
export const AllloseRoute = [
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
